package com.gagakuai.bpm.api.camunda;



import com.gagakuai.bpm.domian.dto.camunda.WorkflowDeploymentDto;
import com.gagakuai.bpm.domian.dto.request.PageRequest;
import com.gagakuai.bpm.domian.dto.response.PageData;
import com.gagakuai.bpm.domian.dto.response.ResponseStatusDto;
import com.gagakuai.bpm.service.camunda.WorkflowDeploymentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;


@RestController
@RequestMapping("/bpm/deploy")
@Api(tags = {"流程部署管理相关接口"})
public class WorkflowDeploymentController {

    @Resource
    private WorkflowDeploymentService workflowDeploymentService;

    @ApiOperation("部署bpmn.xml流程文件")
    @PostMapping("/deploy")
    public ResponseStatusDto<Void> bpmnModelDeployFile(MultipartFile file, String name) {
        workflowDeploymentService.bpmnModelDeployFile(file, name);
        return ResponseStatusDto.success();
    }

    @ApiOperation("分页获取流程部署列表")
    @PostMapping("/list")
    public ResponseStatusDto<PageData<WorkflowDeploymentDto>> listDeploymentByPage(@RequestBody PageRequest<WorkflowDeploymentDto> pageRequest) {

        return ResponseStatusDto.success(workflowDeploymentService.listDeploymentByPage(pageRequest));
    }

    @ApiOperation("重新部署")
    @PostMapping("/redeploy")
    public ResponseStatusDto<Void> redeployResource(@RequestBody WorkflowDeploymentDto dto) {
        workflowDeploymentService.redeployResource(dto);
        return ResponseStatusDto.success();
    }

    @ApiOperation("删除流程部署")
    @PostMapping("/delete")
    public ResponseStatusDto<Void> deleteDeployment(@RequestBody WorkflowDeploymentDto dto) {
        workflowDeploymentService.deleteDeploymet(dto.getId());
        return ResponseStatusDto.success();
    }
}
